extends Node2D
@onready var test_4: Node2D = $"."

var item: Array[Node] = []
var target_position   = Vector2()


func _ready() -> void:
	for i in range(21):
		if i!=0:
			var right_1 = preload("res://layout/test2.tscn").instantiate()
			right_1.position=getVector(i)
			test_4.add_child(right_1)
			right_1.connect("my_signal", Callable(self, "_on_my_signal"))
			item.append(right_1)
			if i> 15:
				right_1.setImage("res://animation/test1.tres", "guard_3", "燕山雪"+str(i))
			elif i> 10:
				right_1.setImage("res://animation/test1.tres", "guard_3", "燕山雪"+str(i))
			elif i> 5:
				right_1.setImage("res://animation/test1.tres", "guard_7", "燕山雪"+str(i))
			else:
				right_1.setImage("res://animation/test1.tres", "guard_7", "燕山雪"+str(i))


func _process(delta: float) -> void:
	pass


#func getVector(index: float) -> Vector2:
#if index> 15:
#return Vector2(400 + 580 - ((index - 15) * 60),((index - 15) * 100) + 70 + 80)
#elif index> 10:
#return Vector2(400 + 480 - ((index - 10) * 60),((index - 10) * 100) + 70 + 40)
#elif index> 5:
#return Vector2(400 + 100 - ((index - 5) * 60),((index - 5) * 100) + 70 + 40)
#else :
#return Vector2(400 - (index * 60),(index * 100) + 70)

func getVector(index: float) -> Vector2:
	if index> 15:
		return Vector2(400 +580-((index-15) *60), ((index - 15)*100)+80)
	elif index> 10:
		return Vector2(400 + 480 - ((index - 10) * 60), ((index - 10)*100)+40)
	elif index> 5:
		return Vector2(400 + 100 - ((index - 5) * 60), ((index - 5)*100)+40)
	else:
		return Vector2(400 - (index * 60), (index * 100) )


func _on_my_signal(info: Vector2, size: Vector2):
	target_position=Vector2(info.x+(size.x/2), info.y)
